package sky.wicket;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sky.tro.CityFinder;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: Gauss
 * Date: 06.10.13
 * Time: 17:34
 * To change this template use File | Settings | File Templates.
 */
public class CityFilter extends BasePage {

    private CityFinder cityFinder = new CityFinder();
    static final Logger log = LoggerFactory.getLogger(AddUpdateCity.class);

    public CityFilter() {
        addElementsToPage();
    }

    private void addElementsToPage() {
        add(new FeedbackPanel("feedback"));
        add(new Label("criteriaLabel", "Criteia: "));
        Form<CityFinder> cityCriteria = new Form<CityFinder>("cityCriteria", new CompoundPropertyModel<CityFinder>(cityFinder)){
            @Override
            protected void onSubmit() {
                log.info("country: " + cityFinder.getCountryName());
                setResponsePage(new CityList(cityFinder));
            }

            @Override
            protected void onError() {}
        };
        cityCriteria.add(new Label("countryNameLabel", "Country's name: "));
        cityCriteria.add(new TextField<String>("countryName"));
        add(cityCriteria);
    }
}
